package com.jwell.panrank.ui.adapter

import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.jwell.panrank.R
import com.jwell.panrank.entity.ForWaybillLogListDto
import com.jwell.panrank.tools.StringUtils
import kotlinx.android.synthetic.main.item_waybill_basic_layout.view.*

/**
 * Created by 76577 on 2018/4/24.
 * 运单详情物流日志适配器
 */
class WaybillInfoLogAdapter constructor(list: List<ForWaybillLogListDto>) : RecyclerView.Adapter<WaybillInfoLogAdapter.ViewHolder>() {
    private var list = list

    override fun getItemCount(): Int {
        return list.size
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent?.context).inflate(R.layout.item_waybill_basic_layout, parent, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        with(holder.itemView) {
            text_time.text = StringUtils.getInstance()
                    .setModal(StringUtils.TIME_TYPE_3)
                    .regularization(list[position].createDate, "T", " ")
            text_content.text = list[position].content ?: ""
            when (position) {
                0 -> {
                    text_content.setTextColor(holder.itemView.resources.getColor(R.color.green))
                    view1.visibility = View.VISIBLE
                    view2.visibility = View.GONE
                }
                else -> {
                    text_content.setTextColor(holder.itemView.resources.getColor(R.color.black))
                    view2.visibility = View.VISIBLE
                    view1.visibility = View.GONE
                }
            }
        }
    }

    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
}